const Router = require('koa-router')
const advise = new Router()
//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
    database: 'running',
    user: 'run',
    port: 5432,
    host: '82.157.94.115',
    password: 'z12345678',
    max: 2
})
function makeId() {
    let id = Math.random().toString(16).substring(2);
    let id2 = Math.random().toString(16).substring(2);
    return (id + id2).substring(0, 12);
}
advise.post('/advise', async ctx => {
    // ctx.body = ''
    let { advise } = ctx.request.body;
    console.log("advise", advise);
    let insertContentPostgresql = `insert into advise (advise_openid,advise_advise,advise_state) values ($1,'${advise}','未读')`;
    let content = await psql.query(insertContentPostgresql, [makeId()]);

    if (content.rowCount > 0)
        ctx.body = {
            advise: advise

        };
})

module.exports = advise